package ACWing._789_第k个数;

import java.util.Arrays;
import java.util.Scanner;

public class Main_quick_select {

    static int quick_sort(int[] a, int l, int r, int k){
        if(l>=r)
            return a[k];
        int i = l-1, j=r+1,x = a[l];
        while (i<j){
            do i++; while (a[i]<x);
            do j--; while (a[j]>x);
            if(i<j) {
                    int temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
            }

            System.out.println(Arrays.toString(a));
            System.out.println(i+","+j);
        }
        if(k > j)  return quick_sort(a,j+1,r,k);
        else return quick_sort(a,l,j,k);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        // 选取第k个数，改造快排
        System.out.println(quick_sort(a, 0, n - 1, k - 1));

        scanner.close();

    }
}
